Object-relational (O-R) technologies enable the relational database world to interact with the object-oriented programming world. Relational database management systems (RDBMS) supporting a relational database pre-dated the popularization of object-oriented programming. Utilizing relational databases to store object-oriented data leads to a semantic gap where programmers are required to design their software to function in two different worlds—processing data in object-oriented form, yet storing the same data in relational form.
Requiring constant conversion between two different forms of the same data not only had the effect of stifling performance but also imposed difficulties for programmers as relational or object-oriented forms would impose limitations on each other. For example, relational databases make complicated associations difficult, and they tend to map poorly into the object-oriented world. This problem is sometimes referred to as the object-relational impedance mismatch.
Generally, relational databases use a series of tables representing simple data, where optional or related information is stored in other tables. A single object record in the database often spans several of these tables, and requires a join to collect all of the related information back into a single piece of data for processing. This would be the case for a sales database, for instance, which would likely include at least a customer and order table and perhaps a sales representative table.
In the object world, there is a clear sense of ownership, where a particular customer object owns a particular order in terms of the aforementioned example. This is not the case in relational databases. The tables have no understanding how they relate to other tables at a fundamental level. Instead, a user needs to construct a query to gather information. Queries not only identify what information to return, but they also have to specify how involved tables are related to each other. Thus, relationships in a relational system are typically known only when a query is run that specifies such relationships.
O-R mappers (ORMs) are often employed to facilitate bridging the gap between the relational and object-oriented worlds. O-R mappers enable queries to be written against a mapped object model instead of an underlying relational model. Classes are mapped to tables and relationships between classes are mapped to foreign keys or similar relationships in a database. For example, customer and order classes are mapped to customer and order tables (e.g., “CustomerTable,” “OrderTable”) while navigational relationships “Customer.Orders” and “Order.Customer” are mapped to the foreign key relationship between corresponding tables.